package com.rk.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rk.admin.domain.Comarticle;
import com.rk.admin.domain.Logs;
import com.rk.admin.mapper.LogsMapper;
import com.rk.admin.service.LogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class LogsServiceImpl implements LogsService {

    @Autowired
    private LogsMapper logsMapper;

//
//    /**
//     * 每天删除7天前的日志
//     */
//    @Scheduled(cron = "0 0 0 1/1 * ? *")
//    public void timingDeleteLogs (){
//        System.err.println(LocalDateTime.now());
//        System.out.println("删除一条日志");
//        logsMapper.timingDeleteLogs();
//    }





    /**
     * 分页条件(操作名称)查询
     *
     * @param page
     * @param limit
     * @param opername
     * @return
     */
    @Override
    public IPage<Logs> selectPage(int page, int limit, String opername) {
        IPage<Logs> pageinfo=new Page<>(page,limit);
        LambdaQueryWrapper<Logs> lqw=new LambdaQueryWrapper<>();
        //根据操作时间降序
        lqw.orderByDesc(Logs::getOpertime);

        //如果操作名不为空
        if(opername!=null&&!opername.equals(""))
        {
            lqw.like(Logs::getOpername,opername);
        }

        //条件分页查询
        logsMapper.selectPage(pageinfo,lqw);

        return pageinfo;
    }

    /**
     * 保存日志
     *
     * @param logs
     * @return
     */
    @Override
    public Boolean save(Logs logs) {
       return logsMapper.insert(logs)>0;
    }
}
